<template>
  <div>
    <header>
      <div class="search">
          <img src="@/assets/search.png" alt="">
          <input type="text" placeholder="黑五嗨购节">
      </div>
    </header>
    <div class="whitespace"/>
    <div class="main">
      <section>
        <ul>
          <li
            v-for="(item, index) of mallList"
            :key="item.mallid"
            @click="reLoadProdList(index)"
            :class="index === page ? 'active' : ''"
          >{{ item.type }}</li>
        </ul>
      </section>
      <div class="container">
        <router-link
          tag="div"
          class="item"
          v-for="(item, index) of data"
          :to="{
            name: 'cates',
            params: {
              id: item.ListId,
              page: page,
              index: index
            }
          }"
          :key="item.ListId"
        >
          <img :src="item.img" alt="">
          <h3>{{ item.title }}</h3>
        </router-link>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Mall',
  data () {
    return {
      mallList: [],
      data: [],
      page: 0
    }
  },
  methods: {
    reLoadProdList (id) {
      this.page = id
      this.$http('/api/Mall').then(resp => {
        this.data = resp.data.res_body.mallList[id].data
        this.data.uid = id
      })
    }
  },
  mounted () {
    this.$http('/api/Mall').then(resp => {
      this.mallList = resp.data.res_body.mallList
      this.data = resp.data.res_body.mallList[this.page].data
    })
  }
}
</script>

<style lang="scss" scoped>
  header {
    height: 46px;
    width: 100%;
    background-color: #fff;
    position: fixed;
    top: 0;
    left: 0;
    padding: 0 12px;
    z-index: 9999;
    border-bottom: 1px solid #eee;
    box-sizing: border-box;
    .search {
      display: flex;
      margin: 9px 0;
      background-color: #eee;
      height: 27px;
      align-items: center;
      img {
        width: 13px;
        height: 13px;
        margin-left: 6px;
      }
      input {
        flex: 1;
        height: 16px;
        border: none;
        background-color: #eee;
        padding-left: 6px;
        font-size: 12px;
        color: #999;
      }
      input:focus {outline: none;}
    }
  }
  .whitespace {
    height: 45px;
    width: 100%;
    background-color: #fff;
  }
  .main {
    display: flex;
    position: relative;
    height: 572px;
    section {
      position: fixed;
      top: 46px;
      left: 0;
      height: 570px;
      padding-top: 13px;
      width: 75px;
      overflow-x: hidden;
      z-index: 0;
      ul {
        height: 558px;
        overflow-x: hidden;
        li {
          box-sizing: border-box;
          text-align: center;
          height: 24px;
          margin-bottom: 20px;
          color: #333;
          line-height: 24px;
          font-size: 12px;
        }
        .active {
          border-left: 3px solid rgb(132, 95, 63);
          color: rgb(132, 95, 63);
          font-size: 13px;
        }
      }
    }
    .container {
      flex: 1;
      padding-top: 40px;
      display: flex;
      margin-left: 75px;
      justify-content: space-between;
      flex-wrap: wrap;
      align-content: flex-start;
      border-left: 1px solid #dedede;
      .item {
        width: 70px;
        margin: 10px;
        margin-bottom: 0;
        height: 103px;
        img {
          float: left;
          width: 70px;
          height: 70px;
        }
        h3 {
          margin-top: 75px;
          font-size: 11px;
          color: rgb(102, 102, 102);
          text-align: center;
        }
      }
    }
  }
</style>
